
import os
from datetime import datetime, timedelta, timezone


f4=open('slevee_rate.txt', encoding='utf-8')
#此时只读取了一行
pre = f4.readline()
pre = pre.replace("\n","")
all_line = []

all_codes = [209,210,211,212]
all_line.append(pre)
all_flaw_types = set()
#利用循环全部读出
i = 1
while pre:
    next_line = f4.readline()
    next_line = next_line.replace("\n", "")
    if next_line:
        parts = next_line.split(",")
        if len(parts) > 1:
            for part in parts:
                if "-" in part:
                    part_items = part.split("-")
                    if len(part_items) > 1:
                        if int(part_items[0]) in all_codes:
                            all_flaw_types.add(int(part_items[1]))
                            all_line.append(part)
        else:
            all_line.append(next_line)
    pre = next_line
f4.close()

print(f"--------all_line : {all_line} ")
print(f"--------all_flaw_types : {all_flaw_types} ")

res = {item: 0 for item in all_flaw_types}
for item in all_line:
    if "-" in item:
        part_items = item.split("-")
        flaw_type = int(part_items[1])
        if flaw_type in all_flaw_types:
            res[flaw_type] += 1
print(f"--------res : {res} ")

for item in res:
    rate = f"{res[item] / len(all_line) * 100}%"
    res[item] = rate

print(f"--------res : {res} ")




